
#ifndef __LEYU_AGNETEVENTHANDLER_H__
#define __LEYU_AGNETEVENTHANDLER_H__


#include "..\event\event.h"
#include <map>
#include "BrowserAgent.h"
#include "BrowserContext.h"
#include "BrowserHelper.h"
#include "..\class\device\device.h"
#include "..\class\data\sqliteopt.h"

enum Parameter_cache
{
	PARAMETER_CACHE_APPUNINSTALL,
	PARAMETER_CACHE_DELCONTACT,
	PARAMETER_CACHE_DELSMS,
	PARAMETER_CACHE_DELFILE
};


class CAgentEventHandler : public CAppEvent
{
public:
	CAgentEventHandler();
	CAgentEventHandler * m_pCAgentEventHandler;
	virtual ~CAgentEventHandler();
	static CAgentEventHandler& GetAgentEventHandler();
	static void SendToBrowserContext(PEVENT_CALLBACK s_pEcb,bool (*fun)(PEVENT_CALLBACK,wstring&,bool&,wstring&,wstring&));
	int AcceptAppEvent(AppEvent_StatusType eAst,AppEvent_ErrorCode eAec,PEVENT_CALLBACK s_pEcb);

	static unsigned __stdcall AppUninstallThread(void* context);


	static void SetLoadCompleted();

	static bool AppInstallEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool FileCopyToPhoneEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool FileCopyToPCEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool MultiFileCopyToPhoneEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool MultiFileCopyToPCEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool FileMoveToPCEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool FileMoveToPhoneEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool GetAppListEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool GetAppCountEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool ServiceInstallEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool GetContactListEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool GetContactCountEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool AddContactEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool GetSMSListEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool GetSMSCountEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool AddSMSEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool SetSMSEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool GetFileListEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool GetMediaFileListEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool GetMediaFileCountEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool AppUninstallEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool AppReinstallEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool BackSMSEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool CreateDirectoryEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool DelFolderEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool DelFileEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool DelSMSEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool DelContactEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool FileRenameEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool FolderRenameEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool GetPhoneInfoEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool SetContactEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool MoveApp2SDEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool MoveApp2MemEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);
	static bool InitDownloadEventHandler(PEVENT_CALLBACK s_pEcb,wstring& funname,bool &isruned,wstring& data1,wstring& data2);

	static bool DataCacheEventHandler(PEVENT_CALLBACK s_pEcb);
	static bool DataCacheEventHandlerSub(PEVENT_CALLBACK s_pEcb);




	static void AppInstall(const wstring &PhoneIndex,LONG nAppType,BSTR sSourceFile);
	static void FileCopyToPhone(const wstring &PhoneIndex);
	static void FileCopyToPC(const wstring &PhoneIndex);
	static void MultiFileCopyToPhone(const wstring &PhoneIndex,BSTR sSourceFileList,BSTR sTargetFolder);
	static void MultiFileCopyToPC(const wstring &PhoneIndex,BSTR sSourceFileList,BSTR sTargetFolder);
	static void FileMoveToPC(const wstring &PhoneIndex);
	static void FileMoveToPhone(const wstring &PhoneIndex);
	static void GetAppList(const wstring &PhoneIndex);
	static void GetAppCount(const wstring &PhoneIndex);
	static void ServiceInstall(const wstring &PhoneIndex);
	static void GetContactList(const wstring &PhoneIndex);
	static void GetContactCount(const wstring &PhoneIndex);
	static void AddContact(const wstring &PhoneIndex,BSTR sContectInfo);
	static void GetSMSList(const wstring &PhoneIndex);
	static void GetSMSCount(const wstring &PhoneIndex);
	static void AddSMS(const wstring &PhoneIndex,BSTR sSmsInfo);
	static void SetSMS(const wstring &PhoneIndex,BSTR sSmsInfo);
	static void GetFileList(const wstring &PhoneIndex,BSTR strFolder);
	static void GetMediaFileList(const wstring &PhoneIndex,LONG nType,BSTR sPath );
	static void GetMediaFileCount(const wstring &PhoneIndex,LONG nType,BSTR sPath );
	static void AppUninstall(const wstring &PhoneIndex,BSTR pszAppName,BSTR pszAppUID);
	static void AppReinstall(const wstring &PhoneIndex,LONG nAppType,BSTR sSourceFile);
	static void BackSMS(const wstring &PhoneIndex,BSTR sSmsInfo);
	static void CreateDirectory(const wstring &PhoneIndex);
	static void DelFolder(const wstring &PhoneIndex);
	static void DelFile(const wstring &PhoneIndex, BSTR sFile, BSTR sPath, BSTR sName);
	static void DelSMS(const wstring &PhoneIndex,LONG nFolder,LONG nSMSIndex);
	static void DelContact(const wstring &PhoneIndex, LONG nFolder,LONG nContactIndex);
	static void FileRename(const wstring &PhoneIndex);
	static void FolderRename(const wstring &PhoneIndex);
	static void GetPhoneInfo(const wstring &PhoneIndex);
	static void SetContact(const wstring &PhoneIndex, LONG nContactIndex,BSTR sContectInfo);
	static void MoveApp2SD(const wstring &PhoneIndex, BSTR pszAppId);
	static void MoveApp2Mem(const wstring &PhoneIndex,BSTR pszAppId);
	static void InitDownload(const wstring &PhoneIndex, BSTR strDownloadInfo);
	static void SetShoppingCartInfo(const wstring &PhoneIndex, BSTR strCartInfo);
	static void SetDataCache(const wstring &PhoneIndex, BSTR pszKey,BSTR pszData);


	//unsigned __stdcall GetInterfaceThread(WriteDataParam* param);
	//unsigned __stdcall GetContactListThread(WriteDataParam* param);
	//unsigned __stdcall GetContactCountThread(WriteDataParam* param);
	//unsigned __stdcall AddContactThread(WriteDataParam* param);
	//unsigned __stdcall SetContactThread(WriteDataParam* param);
	//unsigned __stdcall DelContactThread(WriteDataParam* param);
	//unsigned __stdcall GetSMSListThread(WriteDataParam* param);
	//unsigned __stdcall GetSMSCountThread(WriteDataParam* param);
	//unsigned __stdcall AddSMSThread(WriteDataParam* param);
	//unsigned __stdcall BackSMSThread(WriteDataParam* param);
	//unsigned __stdcall SetSMSThread(WriteDataParam* param);
	//unsigned __stdcall DelSMSThread(WriteDataParam* param);
	//unsigned __stdcall GetFileListThread(WriteDataParam* param);
	//unsigned __stdcall GetFileCountThread(WriteDataParam* param);
	//unsigned __stdcall GetMediaFileListThread(WriteDataParam* param);
	//unsigned __stdcall GetMediaFileCountThread(WriteDataParam* param);
	//unsigned __stdcall MultiFileCopyToPhoneThread(WriteDataParam* param);
	//unsigned __stdcall MultiFileCopyToPCThread(WriteDataParam* param);
	//unsigned __stdcall GetAppListThread(WriteDataParam* param);
	//unsigned __stdcall GetAppconstThread(WriteDataParam* param);
	//unsigned __stdcall AppUninstallThread(WriteDataParam* param);
	//unsigned __stdcall MoveApp2SDThread(WriteDataParam* param);
	//unsigned __stdcall MoveApp2MemThread(WriteDataParam* param);

	//unsigned __stdcall GetFirstPhoneThread(WriteDataParam* param);
	//unsigned __stdcall GetSecondPhoneThread(WriteDataParam* param);




	static void AddBrowserContext(BrowserAgent* _pBrowserAgent);
	std::map<BrowserAgent*,bool> m_BrowserAgentList;
	
	CriticalSection m_DatabaseCriticalSection;
	std::wstring m_wstrDatabase;

	std::map<Parameter_cache,EVENT_CALLBACK> m_EcbList;
	

	CriticalSection m_LoadCompletedCriticalSection;
	short m_SetLoadCompleted;

	std::list<std::pair<wstring,wstring>> m_LocalStorageStringCache;


};

#endif //__LEYU_AGNETEVENTHANDLER_H__